/*
 * 
 * 
 * 
 */
package com.hboxs.asl.service.impl;

import com.hboxs.asl.Page;
import com.hboxs.asl.Pageable;
import com.hboxs.asl.dao.OrderItemDao;
import com.hboxs.asl.dao.ReturnsRecordDao;
import com.hboxs.asl.entity.Member;
import com.hboxs.asl.entity.OrderItem;
import com.hboxs.asl.entity.ReturnsRecord;
import com.hboxs.asl.service.ReturnsRecordService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * Service - 退货记录
 */
@Service("returnsRecordServiceImpl")
public class ReturnsRecordServiceImpl extends BaseServiceImpl<ReturnsRecord, Long> implements ReturnsRecordService {

    @Resource(name = "returnsRecordDaoImpl")
    private ReturnsRecordDao returnsRecordDao;
    @Resource(name = "orderItemDaoImpl")
    private OrderItemDao orderItemDao;

    @Resource(name = "returnsRecordDaoImpl")
    public void setBaseDao(ReturnsRecordDao returnsRecordDao) {
        super.setBaseDao(returnsRecordDao);
    }

    @Override
    public Page<ReturnsRecord> findPage(ReturnsRecord.Reason reason, ReturnsRecord.Status status, Pageable pageable) {
        return returnsRecordDao.findPage(reason, status, pageable);
    }

    @Override
    public void create(Member member, ReturnsRecord.Reason reason, String description, OrderItem oi) {

        ReturnsRecord returnsRecord = new ReturnsRecord();
        returnsRecord.setOrderItem(oi);
        returnsRecord.setDescription(description);
        returnsRecord.setStatus(ReturnsRecord.Status.apply);
        returnsRecord.setReason(reason);
        returnsRecord.setMember(member);
        returnsRecord.setMerchant(oi.getProduct().getMerchant());

        oi.setHasApplyReturn(true);
        orderItemDao.merge(oi);

        save(returnsRecord);
    }


}
